<template>
  <div>
    <h2>事件消息：{{ message }}</h2>
  </div>
</template>

<script setup>
import { ref, onUnmounted } from 'vue';
import { EventBus } from '../utils/event-bus.js';

const message = ref('');

const listener = (msg) => {
  message.value = msg;
};

// 监听事件
EventBus.on('my-event', listener);

// 组件卸载时移除事件监听器
onUnmounted(() => {
  EventBus.off('my-event', listener);
});
</script>